<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
    var s = ' a maz ing ';
    var a = s.trim().split('');
    for (var o in a) {
        if (o === ' ') {
            a.splice(1);
        }
    }
    let s2 = a.join('');
    console.log(s2);
    debugger;
</script>
</body>
</html>